package com.app.piemoment.entity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Subject {

	private String code;
	private String module;
	private String question;
	private String type;
	private String[] answers;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getModule() {
		return module;
	}

	public void setModule(String module) {
		this.module = module;
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String[] getAnswers() {
		return answers;
	}

	public void setAnswers(String[] answers) {
		this.answers = answers;
	}

	public void parser(JSONObject obj) throws JSONException {
		if(obj!=null) {
			setCode(obj.getString("code"));
			setModule(obj.getString("module"));
			setQuestion(obj.getString("question"));
			setType(obj.getString("type"));
			if(obj.has("possible_answers")) {
				JSONArray jsonArray = obj.getJSONArray("possible_answers");
				if(jsonArray!=null&&jsonArray.length()>0) {
					answers = new String[jsonArray.length()];
					for(int i=0;i<jsonArray.length();i++) {
						answers[i] = (String) jsonArray.opt(i);
					}
					setAnswers(answers);
				}
			}
		}
		
	}

}
